using System;
using System.Collections.Generic;
using Core.GameObjects.Items;

namespace Core.GameObjects.Jobs
{
    public enum InteractionType
    {
        Talk,
        Kill
    }

    public enum JobRewardType
    {
        Armor,
        Item,
        Money,
        Spell,
        Weapon
    }

    public class JobStep
    {
        private string _stepName;
        private int _giveItemID;
        private int _getItemID;
        private int _stepEntityID;
        private InteractionType _stepInteractionType;

        // ID of conversation script which is started when StepEntity is interacted with
        private int _conversationID;

        // array of IDs of subJobs
        private List<int> _subJobIDs;

        private List<Item> _requiredItems;

        // required level to start the step, each step may have a different level
        private byte _minimumLevel;

        // number of minutes the step can take
        private long _timeLimit;

        private JobRewardType _rewardItemType;
        private int _rewardItemID;
        private int _rewardMoneyAmount;

        public JobStep()
        {

        }

        public string StepName
        {
            get { return _stepName; }
            set { if (!string.IsNullOrEmpty(value)) _stepName = value; }
        }

        public int GiveItemID
        {
            get { return _giveItemID; }
            set { if (value > 0) _giveItemID = value; }
        }

        public int GetItemID
        {
            get { return _getItemID; }
            set { if (value > 0) _getItemID = value; }
        }

        public int StepEntityID
        {
            get { return _stepEntityID; }
            set { if (value > 0) _stepEntityID = value; }
        }

        public InteractionType StepInteractionType
        {
            get { return _stepInteractionType; }
            set { _stepInteractionType = value; }
        }

        public int ConversationID
        {
            get { return _conversationID; }
            set { if (value > 0) _conversationID = value; }
        }

        public void AddSubJob(int ID)
        {
            if (_subJobIDs == null)
                _subJobIDs = new List<int>();

            _subJobIDs.Add(ID);
        }

        public void InsertSubJobID(int index, int ID)
        {
            if (_subJobIDs == null)
                _subJobIDs = new List<int>();

            if (index <= _subJobIDs.Count - 1)
                _subJobIDs.Insert(index, ID);
            else
                throw new IndexOutOfRangeException("Number of sub-Jobs is less than the index passed to the InsertSubJobID method");
        }

        public List<int> SubJobIDs
        {
            get { return _subJobIDs; }
        }

        public void RemoveSubJobIDByIndex(int index)
        {
            _subJobIDs.RemoveAt(index);
        }

        public void RemoveSubJobIDByID(int ID)
        {
            _subJobIDs.Remove(ID);
        }

        public void AddRequiredItem(Item item)
        {
            if (_requiredItems == null)
                _requiredItems = new List<Item>();

            _requiredItems.Add(item);
        }

        public void RemoveRequiredItemByIndex(int index)
        {
            _requiredItems.RemoveAt(index);
        }

        public void RemoveSubJobIDByItem(Item item)
        {
            _requiredItems.Remove(item);
        }

        public List<Item> RequiredItems
        {
            get { return _requiredItems; }
        }

        public byte MinimumLevel
        {
            get { return _minimumLevel; }
            set { if (value > 0) _minimumLevel = value; }
        }

        public long TimeLimit
        {
            get { return _timeLimit; }
            set { if (value > 0) _timeLimit = value; }
        }

        public JobRewardType RewardItemType
        {
            get { return _rewardItemType; }
            set { _rewardItemType = value; }
        }

        public int RewardItemID
        {
            get { return _rewardItemID; }
            set { if (value > -1) _rewardItemID = value; }
        }

        public int RewardMoneyAmount
        {
            get { return _rewardMoneyAmount; }
            set { if (value > 0) _rewardMoneyAmount = value; }
        }
    }
}
